var initialize_calendar;
initialize_calendar = function () {
    $('#calendar').fullCalendar({
        header: {
            right: 'prevYear,prev,today,next,nextYear',
            left: 'title'
        },
        defaultView: 'month',
        weekNumbers: true,

        contentHeight: 400,
        aspectRatio: 1.5,
        handleWindowResize: false,

        selectable: true,

        dayClick: function (date, jsEvent, view) {

            // alert('Clicked on: ' + date.format());
            var userid = $("#userid").text();
            var d = date.format();
            $.ajax({
                type: "GET",
                url: "/show2?id=" + userid + "&date=" + d,
                dataType: "html",
                success: function (result) {
                    console.log(result);
                    $("#mytasks").empty();
                    $("#mytasks").append(result);
                    // var r = result['products'];
                    // $.each(r, function(i, item){
                    //     console.log(i,item);
                    //     var tr = $('<tr>').append(
                    //         $('<td>').text(item.cname),
                    //         $('<td>').text(item.sname),
                    //         $('<td>').text(item.task),
                    //         $('<td>').text(item.cost),
                    //         $('<td>').text(item.date),
                    //         $('<td>').text(item.cost)

                    //     );
                    //     $("#mytasks").append(result);


                    // });

                }


            })




        },

        "events": [{
            "title": "8",
            "start": "2018-09-04"
        },{
            "title": "8",
            "start": "2018-09-05"
        }
    ],

        eventColor: '#ffffff',
        eventBackgroundColor: '#ffffff',
        eventTextColor: '#000000',

        // eventRender: function (event, element, view) {
        //     $(element).each(function () {
        //         $(this).attr('date-num', event.start.format('YYYY-MM-DD'));
        //     });
        // },
        // eventAfterAllRender: function (view) {
        //     for (cDay = view.start.clone(); cDay.isBefore(view.end); cDay.add(1, 'day')) {
        //         var dateNum = cDay.format('YYYY-MM-DD');
        //         var dayEl = $('.fc-day[data-date="' + dateNum + '"]');
        //         var eventCount = $('.fc-event[date-num="' + dateNum + '"]').length;
        //         if (eventCount) {

        //             dayEl.append(eventCount.toString());

        //         }
        //     }
        // },


        // dayClick: (function() {
        //     var lastThis;
        //     return function(date, jsEvent, view) {
        //         if(lastThis)
        //             lastThis.css('background-color', 'white');
        //         lastThis = $(this);
        //         $(this).css('background-color', 'lightblue');
        //     }
        // })(),

        titleFormat: 'YYYY-MM',
        // axisFormat: 'H:mm',
        // slotMinutes: 15,

        isRTL: false,
        monthNames: ["一月", "二月", "三月", "四月", "五月", "六月", "七月", "八月", "九月", "十月", "十一月", "十二月"],
        monthNamesShort: ["一月", "二月", "三月", "四月", "五月", "六月", "七月", "八月", "九月", "十月", "十一月", "十二月"],
        dayNames: ["星期日", "星期一", "星期二", "星期三", "星期四", "星期五", "星期六"],
        dayNamesShort: ["日", "一", "二", "三", "四", "五", "六"],
        buttonText: {
            today: '今天',
            month: '月',
            week: '周',
            day: '天'
        }

    });
};






jQuery(document).on('turbolinks:load',initialize_calendar);